import type { CartItem } from '@/types/cart'
import http from '@/utils/http'

//
export const postAddToShopping = (skuId: string, count: number) => {
  return http({
    method: 'POST',
    url: `/member/cart`,
    data: {
      skuId,
      count,
    },
  })
}

//  获取购物车列表
export const getCartList = () => {
  return http<CartItem[]>({
    method: 'GET',
    url: '/member/cart',
  })
}
// 删除购物车
export const deleteCart = (data: { ids: string[] }) => {
  return http({
    method: 'DELETE',
    url: '/member/cart',
    data,
  })
}
// 修改购物车状态
/**
 *
 * @param skuId skuId
 * @param data selected 选中状态,count 商品数量
 * @returns
 */
export const putChaneCart = (skuId: string, data: { selected?: boolean; count?: number }) => {
  return http({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
  })
}
// 全选/取消全选购物车

export const putSelectAll = (selected: boolean) => {
  return http({
    method: 'PUT',
    url: `/member/cart/selected`,
    data: {
      selected,
    },
  })
}
